Load libraries (packages)

library("respR") ## respirometry/slope analysis
library("tidyverse") ## data manipulation

Set working directory

setwd("[PATH TO DIRECTORY]")

System1 - Dell

Importing data from firesting for resting

preexperiment_date <- "25 April 2023 11 18AM/All"
postexperiment_date <- "25 April 2023 04 02PM/All"

##--- last fish run in trial ---##
experiment_date <- "25 April 2023 12 29PM/Oxygen"
experiment_date2 <- "25 April 2023 12 29PM/All"

firesting <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1 <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

System2 - Asus

Importing data from firesting for resting

preexperiment_date_asus <- "25 April 2023 11 38AM/All"
postexperiment_date_asus <- "25 April 2023 04 42PM/All"

##--- last fish run in trial ---##
experiment_date_asus <- "25 April 2023 01 20PM/Oxygen"
experiment_date2_asus <- "25 April 2023 01 20PM/All"

firesting_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last_asus <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Chamber volumes

chamber1_dell = 0.04650
chamber2_dell = 0.04593
chamber3_dell = 0.04977
chamber4_dell = 0.04860 

chamber1_asus = 0.04565
chamber2_asus = 0.04573
chamber3_asus = 0.04551
chamber4_asus = 0.04791

Date_tested="2023-04-25"
Clutch = "76" 
Male = "CPRE372" 
Female = "CPRE209"
Population = "Pretty patches"
Tank =378 
salinity =36 
Date_analysed = Sys.Date() 

Replicates

1

Enter specimen data

Replicate = 1 
mass = 0.0005722
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "25 April 2023 11 57AM/Oxygen"
experiment_mmr_date2 <- "25 April 2023 11 57AM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001727797

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0005058425

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  15    1     342.8952 -0.02022829 0.987      NA 6848   7082 12019.57
## 2:  16    1     339.1243 -0.01906990 0.983      NA 7342   7575 12559.55
## 3:  18    1     372.5801 -0.02000013 0.977      NA 8330   8564 13639.31
## 4:  19    1     339.4297 -0.01691163 0.989      NA 8824   9058 14178.81
## 5:  20    1     383.3461 -0.01925692 0.987      NA 9318   9507 14718.66
## 6:  21    1     402.9047 -0.01987710 0.986      NA 9762   9995 15258.91
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 12275.21 99.429 94.529 -0.02022829 0.0007200891   -0.02094837 -0.02094837
## 2: 12814.16 99.273 94.270 -0.01906990 0.0006541426   -0.01972405 -0.01972405
## 3: 13894.67 99.331 94.681 -0.02000013 0.0005221023   -0.02052223 -0.02052223
## 4: 14434.60 99.414 94.964 -0.01691163 0.0004561252   -0.01736775 -0.01736775
## 5: 14974.08 99.715 94.442 -0.01925692 0.0003901542   -0.01964708 -0.01964708
## 6: 15513.81 99.422 94.549 -0.01987710 0.0003241435   -0.02020124 -0.02020124
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.2379310
## 2:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.2240252
## 3:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.2330909
## 4:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.1972624
## 5:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.2231509
## 6:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.2294451
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -415.8179          NA  mgO2/hr/kg   -415.8179
## 2:   -391.5155          NA  mgO2/hr/kg   -391.5155
## 3:   -407.3591          NA  mgO2/hr/kg   -407.3591
## 4:   -344.7438          NA  mgO2/hr/kg   -344.7438
## 5:   -389.9876          NA  mgO2/hr/kg   -389.9876
## 6:   -400.9876          NA  mgO2/hr/kg   -400.9876
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 1 CPRE372 CPRE209 Pretty patches 378 0.0005722 ch4 Dell 0.0486 2023-04-25 2024-06-19 good/good 36 27 401.1336 0.2295286 0.984

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.74
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  7  8  9 11 12 13 16 17 19 20 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.45
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     217.5391 -0.04642884 0.9825913      NA 201    254 2695.76
##   2:  NA    2     217.5156 -0.04642129 0.9825953      NA 200    253 2694.56
##   3:  NA    3     217.4950 -0.04640766 0.9825009      NA 206    259 2701.59
##   4:  NA    4     217.4811 -0.04640544 0.9824987      NA 203    256 2697.95
##   5:  NA    5     217.4680 -0.04640176 0.9825005      NA 202    255 2696.85
##  ---                                                                       
## 206:  NA  206     165.2611 -0.02641220 0.9751514      NA  22     75 2491.15
## 207:  NA  207     165.1678 -0.02636922 0.9752030      NA  18     71 2486.64
## 208:  NA  208     164.9195 -0.02627567 0.9758179      NA  21     74 2490.06
## 209:  NA  209     164.8246 -0.02623640 0.9761811      NA  20     73 2488.97
## 210:  NA  210     164.8226 -0.02623372 0.9762452      NA  19     72 2487.88
##      endtime    oxy endoxy        rate
##   1: 2755.76 92.316 89.666 -0.04642884
##   2: 2754.56 92.373 89.690 -0.04642129
##   3: 2761.59 92.063 89.400 -0.04640766
##   4: 2757.95 92.200 89.576 -0.04640544
##   5: 2756.85 92.267 89.624 -0.04640176
##  ---                                  
## 206: 2551.15 99.508 97.776 -0.02641220
## 207: 2546.64 99.708 97.989 -0.02636922
## 208: 2550.06 99.601 97.799 -0.02627567
## 209: 2548.97 99.661 97.825 -0.02623640
## 210: 2547.88 99.720 97.910 -0.02623372
## 
## Regressions : 210 | Results : 210 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 210 adjusted rate(s):
## Rate          : -0.04642884
## Adjustment    : 0.001727797
## Adjusted Rate : -0.04815664 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 210 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 209 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     217.5391 -0.04642884 0.9825913      NA 201    254 2695.76
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 2755.76 92.316 89.666 -0.04642884 0.001727797   -0.04815664 -0.04815664
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0005722   NA 36 27 1.013253 -0.5469617
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -955.8925          NA  mgO2/hr/kg   -955.8925
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 1 CPRE372 CPRE209 Pretty patches 378 0.0005722 ch4 Dell 0.0486 2023-04-25 2024-06-19 good/good 36 27 401.1336 0.2295286 0.984 955.8925 0.5469617 0.9825913 554.7589 0.317433

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 202 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

2

Enter specimen data

Replicate = 2 
mass = 0.0006898 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_dell
system1 = "Dell"
Notes="resting doesn't look reliable"

##--- time of trail ---## 
experiment_mmr_date <- "25 April 2023 12 08PM/Oxygen"
experiment_mmr_date2 <- "25 April 2023 12 08PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0004168435

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.0009399243

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0     slope_b1   rsq density  row endrow     time
## 1:  13    1     246.9294 -0.013463273 0.971      NA 5861   6094 10938.98
## 2:  15    1     251.8937 -0.012714900 0.977      NA 6848   7082 12019.57
## 3:  16    1     240.1435 -0.011239206 0.986      NA 7342   7575 12559.55
## 4:  17    1     259.8749 -0.012295449 0.988      NA 7836   8069 13099.10
## 5:  18    1     226.3899 -0.009352484 0.953      NA 8330   8564 13639.31
## 6:  19    1     256.7054 -0.011122704 0.987      NA 8824   9058 14178.81
##     endtime    oxy endoxy         rate    adjustment rate.adjusted   rate.input
## 1: 11194.38 99.259 95.989 -0.013463273 -0.0005553547  -0.012907918 -0.012907918
## 2: 12275.21 98.773 95.668 -0.012714900 -0.0007020406  -0.012012859 -0.012012859
## 3: 12814.16 98.787 96.068 -0.011239206 -0.0007752628  -0.010463943 -0.010463943
## 4: 13353.97 98.685 95.581 -0.012295449 -0.0008485141  -0.011446935 -0.011446935
## 5: 13894.67 98.613 96.134 -0.009352484 -0.0009218707  -0.008430613 -0.008430613
## 6: 14434.60 98.756 95.966 -0.011122704 -0.0009951268  -0.010127577 -0.010127577
##    oxy.unit time.unit  volume      mass area  S  t        P    rate.abs
## 1:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.15013720
## 2:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.13972641
## 3:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.12171034
## 4:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.13314392
## 5:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.09805986
## 6:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.11779793
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -217.6532          NA  mgO2/hr/kg   -217.6532
## 2:   -202.5608          NA  mgO2/hr/kg   -202.5608
## 3:   -176.4429          NA  mgO2/hr/kg   -176.4429
## 4:   -193.0182          NA  mgO2/hr/kg   -193.0182
## 5:   -142.1569          NA  mgO2/hr/kg   -142.1569
## 6:   -170.7711          NA  mgO2/hr/kg   -170.7711
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 2 CPRE372 CPRE209 Pretty patches 378 0.0006898 ch3 Dell 0.04977 2023-04-25 2024-06-19 good/good 36 27 192.0892 0.1325032 0.9818

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.74
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,  
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  7  8  9 10 11 14 15 16 17 18 19 22 23 24 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.63
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     248.3889 -0.04674841 0.9977288      NA 173    226 3300.35
##   2:  NA    2     248.1841 -0.04668761 0.9976066      NA 172    225 3299.17
##   3:  NA    3     247.9479 -0.04661582 0.9976476      NA 174    227 3301.44
##   4:  NA    4     247.7670 -0.04656293 0.9973836      NA 171    224 3298.09
##   5:  NA    5     247.7562 -0.04655851 0.9976783      NA 175    228 3302.53
##  ---                                                                       
## 208:  NA  208     189.5063 -0.02868096 0.9776351      NA   5     58 3110.41
## 209:  NA  209     187.3409 -0.02799206 0.9736372      NA   4     57 3109.21
## 210:  NA  210     185.0628 -0.02726699 0.9690716      NA   3     56 3108.12
## 211:  NA  211     182.6584 -0.02650137 0.9641314      NA   2     55 3107.02
## 212:  NA  212     180.8573 -0.02592751 0.9612142      NA   1     54 3105.82
##      endtime     oxy endoxy        rate
##   1: 3360.35  94.114 91.343 -0.04674841
##   2: 3359.17  94.066 91.375 -0.04668761
##   3: 3361.44  94.078 91.303 -0.04661582
##   4: 3358.09  94.107 91.418 -0.04656293
##   5: 3362.53  94.045 91.196 -0.04655851
##  ---                                   
## 208: 3170.41 100.060 98.454 -0.02868096
## 209: 3169.21 100.060 98.497 -0.02799206
## 210: 3168.12 100.060 98.531 -0.02726699
## 211: 3167.02 100.140 98.609 -0.02650137
## 212: 3165.82 100.180 98.645 -0.02592751
## 
## Regressions : 212 | Results : 212 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 212 adjusted rate(s):
## Rate          : -0.04674841
## Adjustment    : 0.0004168435
## Adjusted Rate : -0.04716525 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 212 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 211 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     248.3889 -0.04674841 0.9977288      NA 173    226 3300.35
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 3360.35 94.114 91.343 -0.04674841 0.0004168435   -0.04716525 -0.04716525
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0006898   NA 36 27 1.013253 -0.5485981
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -795.3002          NA  mgO2/hr/kg   -795.3002
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 2 CPRE372 CPRE209 Pretty patches 378 0.0006898 ch3 Dell 0.04977 2023-04-25 2024-06-19 good/good 36 27 192.0892 0.1325032 0.9818 795.3002 0.5485981 0.9977288 603.2109 0.4160949 resting doesn’t look reliable

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 203 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

3

Enter specimen data

Replicate = 3 
mass = 0.0008494 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_dell
system1 = "Dell"
Notes="second cycle used for max"

##--- time of trail ---## 
experiment_mmr_date <- "25 April 2023 12 29PM/Oxygen"
experiment_mmr_date2 <- "25 April 2023 12 29PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001234711

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0001056735

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  15    1     520.2323 -0.03515015 0.999      NA 6848   7082 12019.57
## 2:  16    1     523.7420 -0.03394967 0.998      NA 7342   7575 12559.55
## 3:  17    1     558.2107 -0.03516138 0.997      NA 7836   8069 13099.10
## 4:  19    1     578.9063 -0.03392472 0.997      NA 8824   9058 14178.81
## 5:  20    1     600.7554 -0.03417470 0.998      NA 9318   9507 14718.66
## 6:  21    1     606.1446 -0.03333183 0.999      NA 9762   9995 15258.91
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 12275.21 97.612 88.659 -0.03515015  3.036289e-04   -0.03545377 -0.03545377
## 2: 12814.16 97.388 88.550 -0.03394967  2.426969e-04   -0.03419237 -0.03419237
## 3: 13353.97 97.452 88.548 -0.03516138  1.817406e-04   -0.03534312 -0.03534312
## 4: 14434.60 97.510 89.281 -0.03392472  5.973658e-05   -0.03398445 -0.03398445
## 5: 14974.08 97.606 88.902 -0.03417470 -1.218003e-06   -0.03417348 -0.03417348
## 6: 15513.81 97.467 88.998 -0.03333183 -6.220929e-05   -0.03326962 -0.03326962
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3805602
## 2:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3670204
## 3:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3793724
## 4:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3647886
## 5:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3668176
## 6:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.3571155
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -448.0342          NA  mgO2/hr/kg   -448.0342
## 2:   -432.0937          NA  mgO2/hr/kg   -432.0937
## 3:   -446.6358          NA  mgO2/hr/kg   -446.6358
## 4:   -429.4662          NA  mgO2/hr/kg   -429.4662
## 5:   -431.8549          NA  mgO2/hr/kg   -431.8549
## 6:   -420.4327          NA  mgO2/hr/kg   -420.4327
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 3 CPRE372 CPRE209 Pretty patches 378 0.0008494 ch2 Dell 0.04593 2023-04-25 2024-06-19 good/good 36 27 437.6169 0.3717118 0.9978

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.36
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     405.8631 -0.06848702 0.9622895      NA  76    129 4500.32
##   2:  NA    2     405.7467 -0.06845939 0.9620833      NA  77    130 4501.42
##   3:  NA    3     405.5833 -0.06839702 0.9590749      NA  92    145 4518.26
##   4:  NA    4     405.1139 -0.06829359 0.9589198      NA  93    146 4519.35
##   5:  NA    5     404.8633 -0.06823869 0.9588853      NA  91    144 4517.14
##  ---                                                                       
## 206:  NA  206     168.1811 -0.01568722 0.9743793      NA   4     57 4417.86
## 207:  NA  207     168.0784 -0.01566420 0.9743375      NA   5     58 4418.99
## 208:  NA  208     167.9496 -0.01563523 0.9741429      NA   3     56 4416.77
## 209:  NA  209     167.6418 -0.01556622 0.9735185      NA   2     55 4415.69
## 210:  NA  210     167.3262 -0.01549536 0.9730028      NA   1     54 4414.57
##      endtime    oxy endoxy        rate
##   1: 4560.32 97.290 93.657 -0.06848702
##   2: 4561.42 97.357 93.713 -0.06845939
##   3: 4578.26 96.503 92.401 -0.06839702
##   4: 4579.35 96.486 92.429 -0.06829359
##   5: 4577.14 96.537 92.454 -0.06823869
##  ---                                  
## 206: 4477.86 98.859 97.930 -0.01568722
## 207: 4478.99 98.876 97.916 -0.01566420
## 208: 4476.77 98.853 97.960 -0.01563523
## 209: 4475.69 98.875 97.970 -0.01556622
## 210: 4474.57 98.870 98.007 -0.01549536
## 
## Regressions : 210 | Results : 210 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 210 adjusted rate(s):
## Rate          : -0.06848702
## Adjustment    : 0.001234711
## Adjusted Rate : -0.06972173 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 11 rate(s) removed, 199 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 198 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     405.8631 -0.06848702 0.9622895      NA  76    129 4500.32
##    endtime   oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 4560.32 97.29 93.657 -0.06848702 0.001234711   -0.06972173 -0.06972173
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0008494   NA 36 27 1.013253 -0.7483919
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:    -881.083          NA  mgO2/hr/kg    -881.083
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 3 CPRE372 CPRE209 Pretty patches 378 0.0008494 ch2 Dell 0.04593 2023-04-25 2024-06-19 good/good 36 27 437.6169 0.3717118 0.9978 881.083 0.7483919 0.9622895 443.466 0.37668 second cycle used for max

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 204 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

4

Enter specimen data

Replicate = 4 
mass = 0.0007347
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "25 April 2023 12 29PM/Oxygen"
experiment_mmr_date2 <- "25 April 2023 12 29PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0004732062

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001811963

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE)  
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     265.2023 -0.02741675 0.976      NA 1460   1688  6079.57
## 2:  12    1     388.9540 -0.02794783 0.996      NA 5369   5601 10399.21
## 3:  13    1     404.9179 -0.02793381 0.993      NA 5861   6094 10938.98
## 4:  15    1     434.2267 -0.02791188 0.993      NA 6848   7082 12019.57
## 5:  16    1     449.1061 -0.02791767 0.993      NA 7342   7575 12559.55
## 6:  19    1     482.5984 -0.02702941 0.986      NA 8824   9058 14178.81
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  6334.58 97.877 91.263 -0.02741675 -0.0007816552   -0.02663509 -0.02663509
## 2: 10653.79 98.084 90.849 -0.02794783 -0.0013601524   -0.02658768 -0.02658768
## 3: 11194.38 99.034 91.949 -0.02793381 -0.0014324983   -0.02650131 -0.02650131
## 4: 12275.21 98.711 91.834 -0.02791188 -0.0015772369   -0.02633464 -0.02633464
## 5: 12814.16 98.169 91.127 -0.02791767 -0.0016494870   -0.02626818 -0.02626818
## 6: 14434.60 98.939 92.250 -0.02702941 -0.0018664323   -0.02516298 -0.02516298
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2894488
## 2:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2889335
## 3:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2879949
## 4:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2861836
## 5:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2854614
## 6:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.2734509
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -393.9686          NA  mgO2/hr/kg   -393.9686
## 2:   -393.2673          NA  mgO2/hr/kg   -393.2673
## 3:   -391.9898          NA  mgO2/hr/kg   -391.9898
## 4:   -389.5245          NA  mgO2/hr/kg   -389.5245
## 5:   -388.5415          NA  mgO2/hr/kg   -388.5415
## 6:   -372.1940          NA  mgO2/hr/kg   -372.1940
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 4 CPRE372 CPRE209 Pretty patches 378 0.0007347 ch1 Dell 0.0465 2023-04-25 2024-06-19 good/good 36 27 391.4583 0.2876044 0.9902

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 3.19
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.36
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     435.2885 -0.07383630 0.9614626      NA 210    263 4653.95
##   2:  NA    2     424.9776 -0.07163800 0.9561962      NA 209    262 4652.60
##   3:  NA    3     422.5642 -0.07112145 0.9539073      NA 208    261 4651.52
##   4:  NA    4     415.5895 -0.06963237 0.9501261      NA 207    260 4650.41
##   5:  NA    5     404.0230 -0.06716336 0.9450891      NA 206    259 4649.07
##  ---                                                                       
## 206:  NA  206     163.3652 -0.01506575 0.9682733      NA  82    135 4506.93
## 207:  NA  207     163.2731 -0.01504714 0.9686503      NA  86    139 4511.40
## 208:  NA  208     162.7341 -0.01492722 0.9702156      NA  83    136 4508.02
## 209:  NA  209     162.6769 -0.01491538 0.9702911      NA  85    138 4510.23
## 210:  NA  210     162.3670 -0.01484675 0.9709382      NA  84    137 4509.15
##      endtime    oxy endoxy        rate
##   1: 4713.95 91.203 87.076 -0.07383630
##   2: 4712.60 91.236 87.116 -0.07163800
##   3: 4711.52 91.276 87.208 -0.07112145
##   4: 4710.41 91.300 87.285 -0.06963237
##   5: 4709.07 91.352 87.419 -0.06716336
##  ---                                  
## 206: 4566.93 95.564 94.543 -0.01506575
## 207: 4571.40 95.384 94.396 -0.01504714
## 208: 4568.02 95.508 94.514 -0.01492722
## 209: 4570.23 95.421 94.449 -0.01491538
## 210: 4569.15 95.440 94.501 -0.01484675
## 
## Regressions : 210 | Results : 210 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 210 adjusted rate(s):
## Rate          : -0.0738363
## Adjustment    : -0.0004732062
## Adjusted Rate : -0.07336309 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 35 rate(s) removed, 175 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 174 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0   slope_b1       rsq density row endrow    time
## 1:  NA    1     435.2885 -0.0738363 0.9614626      NA 210    263 4653.95
##    endtime    oxy endoxy       rate    adjustment rate.adjusted  rate.input
## 1: 4713.95 91.203 87.076 -0.0738363 -0.0004732062   -0.07336309 -0.07336309
##    oxy.unit time.unit volume      mass area  S  t        P  rate.abs
## 1:     %Air       sec 0.0465 0.0007347   NA 36 27 1.013253 -0.797251
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1085.138          NA  mgO2/hr/kg   -1085.138
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 4 CPRE372 CPRE209 Pretty patches 378 0.0007347 ch1 Dell 0.0465 2023-04-25 2024-06-19 good/good 36 27 391.4583 0.2876044 0.9902 1085.138 0.797251 0.9614626 693.6798 0.5096466

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 205 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

5

Enter specimen data

Replicate = 5 
mass = 0.0008519 
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "25 April 2023 12 49PM/Oxygen"
experiment_mmr_date2_asus <- "25 April 2023 12 49PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.00117546

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.002594326

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 5.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 14 15 16 17 19 20 21 22 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 4.60
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   3    1     311.1515 -0.02879079 0.963      NA  820   1006  7432.76
## 2:  10    1     421.0810 -0.02881915 0.990      NA 3576   3762 11212.93
## 3:  15    1     471.6930 -0.02688041 0.992      NA 5371   5557 13913.22
## 4:  16    1     527.3956 -0.02974316 0.992      NA 5765   5951 14453.39
## 5:  18    1     570.8337 -0.03040442 0.985      NA 6553   6739 15533.53
## 6:  21    1     621.1524 -0.03049006 0.992      NA 7734   7920 17153.51
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1:  7687.74 97.183 88.669 -0.02879079 -0.001758196   -0.02703259 -0.02703259
## 2: 11467.73 98.087 90.595 -0.02881915 -0.002434884   -0.02638427 -0.02638427
## 3: 14168.19 97.726 90.524 -0.02688041 -0.002918289   -0.02396213 -0.02396213
## 4: 14708.71 97.471 90.079 -0.02974316 -0.003015018   -0.02672814 -0.02672814
## 5: 15788.41 98.390 90.945 -0.03040442 -0.003208339   -0.02719608 -0.02719608
## 6: 17408.45 98.072 90.474 -0.03049006 -0.003498344   -0.02699172 -0.02699172
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.3026763
## 2:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.2954171
## 3:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.2682971
## 4:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.2992674
## 5:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.3045067
## 6:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.3022186
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -355.2955          NA  mgO2/hr/kg   -355.2955
## 2:   -346.7744          NA  mgO2/hr/kg   -346.7744
## 3:   -314.9397          NA  mgO2/hr/kg   -314.9397
## 4:   -351.2941          NA  mgO2/hr/kg   -351.2941
## 5:   -357.4442          NA  mgO2/hr/kg   -357.4442
## 6:   -354.7583          NA  mgO2/hr/kg   -354.7583
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 5 CPRE372 CPRE209 Pretty patches 378 0.0008519 ch4 Asus 0.04791 2023-04-25 2024-06-19 good/good 36 27 353.1133 0.3008172 0.9844

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 4.06
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  5  6  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.47
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     421.8373 -0.07233110 0.9848693      NA 141    186 4594.76
##   2:  NA    2     421.7028 -0.07229795 0.9847387      NA 143    188 4597.47
##   3:  NA    3     421.2306 -0.07219790 0.9844589      NA 142    187 4596.13
##   4:  NA    4     420.4762 -0.07203915 0.9838882      NA 140    185 4593.39
##   5:  NA    5     418.7944 -0.07166834 0.9834280      NA 144    189 4598.82
##  ---                                                                       
## 172:  NA  172     199.3778 -0.02325069 0.9127906      NA   5     50 4409.41
## 173:  NA  173     198.7788 -0.02310972 0.9037275      NA  17     62 4425.77
## 174:  NA  174     198.4427 -0.02303561 0.9021881      NA  16     61 4424.42
## 175:  NA  175     197.8942 -0.02292635 0.9050821      NA  26     71 4438.05
## 176:  NA  176     197.7853 -0.02290100 0.9051389      NA  25     70 4436.68
##      endtime    oxy endoxy        rate
##   1: 4654.76 89.204 85.327 -0.07233110
##   2: 4657.47 89.222 85.155 -0.07229795
##   3: 4656.13 89.184 85.301 -0.07219790
##   4: 4653.39 89.238 85.423 -0.07203915
##   5: 4658.82 89.090 85.162 -0.07166834
##  ---                                  
## 172: 4469.41 96.986 95.473 -0.02325069
## 173: 4485.77 96.446 95.224 -0.02310972
## 174: 4484.42 96.497 95.326 -0.02303561
## 175: 4498.05 96.450 94.671 -0.02292635
## 176: 4496.68 96.462 94.784 -0.02290100
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.0723311
## Adjustment    : -0.00117546
## Adjusted Rate : -0.07115564 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 69 rate(s) removed, 107 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 106 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0   slope_b1       rsq density row endrow    time
## 1:  NA    1     421.8373 -0.0723311 0.9848693      NA 141    186 4594.76
##    endtime    oxy endoxy       rate  adjustment rate.adjusted  rate.input
## 1: 4654.76 89.204 85.327 -0.0723311 -0.00117546   -0.07115564 -0.07115564
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.0008519   NA 36 27 1.013253 -0.7967095
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -935.2148          NA  mgO2/hr/kg   -935.2148
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 5 CPRE372 CPRE209 Pretty patches 378 0.0008519 ch4 Asus 0.04791 2023-04-25 2024-06-19 good/good 36 27 353.1133 0.3008172 0.9844 935.2148 0.7967095 0.9848693 582.1015 0.4958923
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 206 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

6

Enter specimen data

Replicate = 6 
mass = 0.0008348 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "25 April 2023 12 59PM/Oxygen"
experiment_mmr_date2_asus <- "25 April 2023 12 59PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.001882905

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.003234965

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 5.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 14 15 16 17 19 20 21 22 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 4.60
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  12    1     565.1534 -0.03805008 0.991      NA 4340   4447 12290.70
## 2:  13    1     582.5501 -0.03772299 0.993      NA 4585   4763 12833.41
## 3:  14    1     616.1533 -0.03878507 0.987      NA 4978   5156 13373.82
## 4:  15    1     634.1559 -0.03854436 0.991      NA 5371   5550 13913.22
## 5:  17    1     665.3926 -0.03789142 0.992      NA 6159   6338 14993.41
## 6:  19    1     614.9632 -0.03219717 0.991      NA 6947   7125 16073.42
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 12537.91 97.416 88.304 -0.03805008 -0.003266234   -0.03478384 -0.03478384
## 2: 13077.88 98.354 89.386 -0.03772299 -0.003358579   -0.03436441 -0.03436441
## 3: 13618.01 97.370 88.412 -0.03878507 -0.003450741   -0.03533433 -0.03533433
## 4: 14158.61 97.961 88.507 -0.03854436 -0.003542857   -0.03500151 -0.03500151
## 5: 15238.70 97.321 87.585 -0.03789142 -0.003727113   -0.03416431 -0.03416431
## 6: 16317.59 97.651 89.503 -0.03219717 -0.003911252   -0.02828592 -0.02828592
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3699550
## 2:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3654940
## 3:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3758099
## 4:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3722700
## 5:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3633657
## 6:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -0.3008442
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -443.1660          NA  mgO2/hr/kg   -443.1660
## 2:   -437.8222          NA  mgO2/hr/kg   -437.8222
## 3:   -450.1795          NA  mgO2/hr/kg   -450.1795
## 4:   -445.9392          NA  mgO2/hr/kg   -445.9392
## 5:   -435.2727          NA  mgO2/hr/kg   -435.2727
## 6:   -360.3788          NA  mgO2/hr/kg   -360.3788
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 6 CPRE372 CPRE209 Pretty patches 378 0.0008348 ch3 Asus 0.04551 2023-04-25 2024-06-19 good/good 36 27 442.4759 0.3693789 0.9908

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 4.06
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row+50, # custom
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 11 12 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.41
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     588.4666 -0.09715171 0.9934584      NA  24     69 5124.65
##   2:  NA    2     588.1830 -0.09709951 0.9933396      NA  23     68 5123.29
##   3:  NA    3     587.6614 -0.09699279 0.9930890      NA  25     70 5126.02
##   4:  NA    4     587.1199 -0.09689593 0.9928732      NA  22     67 5121.95
##   5:  NA    5     585.4695 -0.09657824 0.9921490      NA  21     66 5120.60
##  ---                                                                       
## 122:  NA  122     395.3371 -0.06002377 0.9909447      NA 122    167 5258.09
## 123:  NA  123     394.9616 -0.05995114 0.9906726      NA 123    168 5259.45
## 124:  NA  124     394.3386 -0.05983158 0.9901810      NA 124    169 5260.83
## 125:  NA  125     392.4107 -0.05946572 0.9888731      NA 125    170 5262.20
## 126:  NA  126     389.4911 -0.05891289 0.9871747      NA 126    171 5263.57
##      endtime    oxy endoxy        rate
##   1: 5184.65 90.362 85.079 -0.09715171
##   2: 5183.29 90.452 85.156 -0.09709951
##   3: 5186.02 90.302 84.998 -0.09699279
##   4: 5181.95 90.542 85.246 -0.09689593
##   5: 5180.60 90.597 85.260 -0.09657824
##  ---                                  
## 122: 5318.09 79.718 76.282 -0.06002377
## 123: 5319.45 79.548 76.259 -0.05995114
## 124: 5320.83 79.461 76.220 -0.05983158
## 125: 5322.20 79.471 76.177 -0.05946572
## 126: 5323.57 79.460 76.127 -0.05891289
## 
## Regressions : 126 | Results : 126 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 126 adjusted rate(s):
## Rate          : -0.09715171
## Adjustment    : -0.001882905
## Adjusted Rate : -0.09526881 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 126 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 125 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     588.4666 -0.09715171 0.9934584      NA  24     69 5124.65
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 5184.65 90.362 85.079 -0.09715171 -0.001882905   -0.09526881 -0.09526881
##    oxy.unit time.unit  volume      mass area  S  t        P  rate.abs
## 1:     %Air       sec 0.04551 0.0008348   NA 36 27 1.013253 -1.013263
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1213.779          NA  mgO2/hr/kg   -1213.779
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 6 CPRE372 CPRE209 Pretty patches 378 0.0008348 ch3 Asus 0.04551 2023-04-25 2024-06-19 good/good 36 27 442.4759 0.3693789 0.9908 1213.779 1.013263 0.9934584 771.303 0.6438838
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 207 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

7

Enter specimen data

Replicate = 7 
mass = 0.0006609 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "25 April 2023 01 09PM/Oxygen"
experiment_mmr_date2_asus <- "25 April 2023 01 09PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001043411

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001374777

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 5.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 14 15 16 17 19 20 21 22 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 4.60
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  13    1     407.8710 -0.02400412 0.966      NA 4585   4763 12833.41
## 2:  15    1     502.3785 -0.02898336 0.993      NA 5371   5550 13913.22
## 3:  16    1     525.6551 -0.02951103 0.996      NA 5765   5943 14453.39
## 4:  17    1     519.7442 -0.02806128 0.983      NA 6159   6338 14993.41
## 5:  20    1     557.4313 -0.02756454 0.990      NA 7341   7519 16614.22
## 6:  21    1     550.4077 -0.02629504 0.981      NA 7734   7913 17153.51
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 13077.88 99.474 92.988 -0.02400412 -0.001595863   -0.02240826 -0.02240826
## 2: 14158.61 98.806 92.302 -0.02898336 -0.001925448   -0.02705791 -0.02705791
## 3: 14697.72 98.894 91.707 -0.02951103 -0.002090090   -0.02742094 -0.02742094
## 4: 15238.70 98.885 92.090 -0.02806128 -0.002254994   -0.02580628 -0.02580628
## 5: 16858.17 99.239 92.752 -0.02756454 -0.002749292   -0.02481525 -0.02481525
## 6: 17398.91 99.233 92.879 -0.02629504 -0.002914048   -0.02338099 -0.02338099
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2394825
## 2:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2891744
## 3:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2930542
## 4:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2757980
## 5:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2652066
## 6:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.2498783
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -362.3582          NA  mgO2/hr/kg   -362.3582
## 2:   -437.5464          NA  mgO2/hr/kg   -437.5464
## 3:   -443.4169          NA  mgO2/hr/kg   -443.4169
## 4:   -417.3068          NA  mgO2/hr/kg   -417.3068
## 5:   -401.2810          NA  mgO2/hr/kg   -401.2810
## 6:   -378.0880          NA  mgO2/hr/kg   -378.0880
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 7 CPRE372 CPRE209 Pretty patches 378 0.0006609 ch2 Asus 0.04573 2023-04-25 2024-06-19 good/good 36 27 415.5278 0.2746223 0.9886

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 4.06
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.start.row + 125, # custom
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  6  7  8 10 11 12 13 14 15 16 17 18 20 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.73
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##     rep rank intercept_b0    slope_b1       rsq density row endrow    time
##  1:  NA    1     405.2633 -0.05404713 0.9887065      NA  45     89 5678.64
##  2:  NA    2     404.5501 -0.05392165 0.9884361      NA  46     90 5680.00
##  3:  NA    3     404.1129 -0.05384640 0.9881949      NA  44     88 5677.26
##  4:  NA    4     402.0641 -0.05348842 0.9870452      NA  43     87 5675.88
##  5:  NA    5     401.9280 -0.05346200 0.9875010      NA  47     91 5681.37
## ---                                                                       
## 78:  NA   78     308.4504 -0.03701468 0.9451858      NA   5     49 5623.65
## 79:  NA   79     304.1268 -0.03625112 0.9378659      NA   4     48 5622.28
## 80:  NA   80     300.0479 -0.03553095 0.9293456      NA   3     47 5620.91
## 81:  NA   81     296.1416 -0.03484129 0.9202496      NA   2     46 5619.55
## 82:  NA   82     291.8320 -0.03407973 0.9111639      NA   1     45 5618.20
##     endtime     oxy endoxy        rate
##  1: 5738.64  98.224 95.163 -0.05404713
##  2: 5740.00  98.256 95.136 -0.05392165
##  3: 5737.26  98.224 95.232 -0.05384640
##  4: 5735.88  98.255 95.337 -0.05348842
##  5: 5741.37  98.253 95.145 -0.05346200
## ---                                   
## 78: 5683.65  99.962 98.060 -0.03701468
## 79: 5682.28  99.955 98.170 -0.03625112
## 80: 5680.91  99.966 98.253 -0.03553095
## 81: 5679.55 100.010 98.256 -0.03484129
## 82: 5678.20 100.040 98.224 -0.03407973
## 
## Regressions : 82 | Results : 82 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 82 adjusted rate(s):
## Rate          : -0.05404713
## Adjustment    : 0.001043411
## Adjusted Rate : -0.05509054 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 3 rate(s) removed, 79 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 78 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     405.2633 -0.05404713 0.9887065      NA  45     89 5678.64
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 5738.64 98.224 95.163 -0.05404713 0.001043411   -0.05509054 -0.05509054
##    oxy.unit time.unit  volume      mass area  S  t        P  rate.abs
## 1:     %Air       sec 0.04573 0.0006609   NA 36 27 1.013253 -0.588766
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -890.8548          NA  mgO2/hr/kg   -890.8548
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 7 CPRE372 CPRE209 Pretty patches 378 0.0006609 ch2 Asus 0.04573 2023-04-25 2024-06-19 good/good 36 27 415.5278 0.2746223 0.9886 890.8548 0.588766 0.9887065 475.327 0.3141436
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 208 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

8

Enter specimen data

Replicate = 8 
mass = 0.0007650 
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_asus
system1 = "Asus"
Notes="max maybe not reliable"

##--- time of trail ---## 
experiment_mmr_date_asus <- "25 April 2023 01 20PM/Oxygen"
experiment_mmr_date2_asus <- "25 April 2023 01 20PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0008186041

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001890476

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 5.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 14 15 16 17 19 20 21 22 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 4.60
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 2 rate(s) removed, 19 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 13 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   3    1     172.6743 -0.01024603 0.968      NA  820    999  7432.76
## 2:   5    1     206.1458 -0.01277578 0.969      NA 1607   1786  8512.77
## 3:   6    1     234.4559 -0.01504670 0.966      NA 2002   2181  9054.10
## 4:  15    1     306.7904 -0.01510172 0.988      NA 5371   5550 13913.22
## 5:  19    1     375.8525 -0.01733471 0.986      NA 6947   7125 16073.42
## 6:  20    1     308.0431 -0.01269011 0.966      NA 7341   7519 16614.22
##     endtime    oxy endoxy        rate   adjustment rate.adjusted   rate.input
## 1:  7678.16 96.152 93.816 -0.01024603 -0.001258180  -0.008987848 -0.008987848
## 2:  8758.09 96.956 93.958 -0.01277578 -0.001404230  -0.011371550 -0.011371550
## 3:  9299.35 97.736 94.102 -0.01504670 -0.001477432  -0.013569270 -0.013569270
## 4: 14158.61 96.348 92.642 -0.01510172 -0.002134564  -0.012967152 -0.012967152
## 5: 16317.59 96.810 92.738 -0.01733471 -0.002426616  -0.014908092 -0.014908092
## 6: 16858.17 96.912 93.711 -0.01269011 -0.002499736  -0.010190370 -0.010190370
##    oxy.unit time.unit  volume     mass area  S  t        P    rate.abs
## 1:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.09588727
## 2:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.12131791
## 3:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.14476439
## 4:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.13834066
## 5:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.15904767
## 6:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.10871643
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -125.3428          NA  mgO2/hr/kg   -125.3428
## 2:   -158.5855          NA  mgO2/hr/kg   -158.5855
## 3:   -189.2345          NA  mgO2/hr/kg   -189.2345
## 4:   -180.8375          NA  mgO2/hr/kg   -180.8375
## 5:   -207.9055          NA  mgO2/hr/kg   -207.9055
## 6:   -142.1130          NA  mgO2/hr/kg   -142.1130
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
76 8 CPRE372 CPRE209 Pretty patches 378 0.000765 ch1 Asus 0.04565 2023-04-25 2024-06-19 good/good 36 27 175.7352 0.1344374 0.975

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 5.57
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8 12 13 14 15 17 18 19 20 21 22 23 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.57
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     357.4787 -0.04046939 0.9972770      NA 146    190 6507.72
##   2:  NA    2     357.2961 -0.04044145 0.9972769      NA 145    189 6506.38
##   3:  NA    3     357.0274 -0.04040063 0.9971978      NA 144    188 6505.03
##   4:  NA    4     356.2276 -0.04027804 0.9972206      NA 147    191 6509.14
##   5:  NA    5     355.7254 -0.04020178 0.9967202      NA 143    187 6503.66
##  ---                                                                       
## 172:  NA  172     218.9238 -0.01897761 0.9542129      NA   5     49 6314.02
## 173:  NA  173     216.4555 -0.01858878 0.9500339      NA   4     48 6312.67
## 174:  NA  174     214.8451 -0.01833523 0.9464634      NA   3     47 6311.31
## 175:  NA  175     213.3920 -0.01810600 0.9456973      NA   2     46 6309.91
## 176:  NA  176     211.4429 -0.01779854 0.9440809      NA   1     45 6308.53
##      endtime    oxy endoxy        rate
##   1: 6567.72 94.123 91.678 -0.04046939
##   2: 6566.38 94.126 91.777 -0.04044145
##   3: 6565.03 94.129 91.809 -0.04040063
##   4: 6569.14 94.105 91.679 -0.04027804
##   5: 6563.66 94.176 91.891 -0.04020178
##  ---                                  
## 172: 6374.02 98.975 97.914 -0.01897761
## 173: 6372.67 99.003 97.992 -0.01858878
## 174: 6371.31 99.090 97.967 -0.01833523
## 175: 6369.91 99.080 97.993 -0.01810600
## 176: 6368.53 99.077 97.942 -0.01779854
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.04046939
## Adjustment    : -0.0008186041
## Adjusted Rate : -0.03965079 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 176 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 175 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1      rsq density row endrow    time
## 1:  NA    1     357.4787 -0.04046939 0.997277      NA 146    190 6507.72
##    endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 6567.72 94.123 91.678 -0.04046939 -0.0008186041   -0.03965079 -0.03965079
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04565 0.000765   NA 36 27 1.013253 -0.4230163
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -552.9625          NA  mgO2/hr/kg   -552.9625
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
76 8 CPRE372 CPRE209 Pretty patches 378 0.000765 ch1 Asus 0.04565 2023-04-25 2024-06-19 good/good 36 27 175.7352 0.1344374 0.975 552.9625 0.4230163 0.997277 377.2273 0.2885789 max maybe not reliable
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 209 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)